/**
 * @file goods.js
 * @author swan
 */
const app = getApp()
var goodsData = require('../../data/goods-data.js')

Page({
    data: {
        host: getApp().getUrl(),
        curNav:'',
        curIndex:''
    },
    onLoad: function () {
        swan.showToast({
            title: '正在加载...',
            icon: 'loading',
            duration: 1500
        });
        swan.request({
            url: getApp().getUrl('/v1/category-list'),
            success: res => {
                let data = res.data.data;
                this.setData({
                    goodsCategoryList: data,
                })
                for(var key in data){
                    this.setData({
                        curNav: key,
                        curIndex: key
                    })
                    return;
                }
            },
            fail: err => {
                swan.showToast({
                    title: '商品展示失败',
                    icon: 'none'
                });
            }
        });
        
    },
    onSwitchRightTab:function (event) {
        let id = event.target.dataset.id,  
        index = event.target.dataset.index;  
        this.setData({  
            curNav: id,  
            curIndex: index  
        })  
    },
    onGoodsTap:function(event){
        var goodsId = event.currentTarget.dataset.goodsId;
        swan.navigateTo({
            url: "../goods/goods-detail/goods-detail?id=" + goodsId
        })
    },
    onSearchViewTap(e){
        swan.navigateTo({
            url: "../goods/goods-search/goods-search"
        })
    },
    onPullDownRefresh(e) {
        var that = this;
        that.onLoad();    //刷新页面
        setTimeout(function () {
            swan.stopPullDownRefresh();    //停止下拉动作
        }, 1000)
    },
});
